package solutions.leetcode.normal

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/maximum-xor-for-each-query/">1829. 每个查询的最大异或值</a>
 */
private class Solution1829 {
    fun getMaximumXor(nums: IntArray, maximumBit: Int): IntArray {
        val rst = IntArray(nums.size)
        val sum = Math.pow(2.0, maximumBit.toDouble()).toInt()
        var now = 0
        for ((ind, item) in nums.withIndex()) {
            now = now xor item
            rst[nums.size - 1 - ind] = sum - 1 - now % sum
        }
        return rst
    }
}

fun main() {
    println(Solution1829().getMaximumXor(
        arrayOf(0,1,2,2,5,7).toIntArray(),
        3
    ).toList())
}